<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/pagelet/page-includes.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
</head>
<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">
		<%@ include file="/WEB-INF/views/pagelet/top.jsp"%>
		<%@ include file="/WEB-INF/views/pagelet/left.jsp"%>
		<div class="content-wrapper">
			<%@ include file="/WEB-INF/views/pagelet/content-header.jsp"%>
			<section class="content">
<!-- 内容开始 -->
				<div id="toolbar">
					<button id="add" class="btn btn-primary" onclick="add()">
						<i class="fa fa-plus"></i> 新增
					</button>
					<button id="update" class="btn btn-warning" disabled onclick="update()">
						<i class="fa fa-edit "></i> 修改
					</button>
					<button id="del" class="btn btn-danger" disabled onclick="del()">
						<i class="fa fa-close "></i> 删除
					</button>
				</div>
				<table id="table"></table>

<!-- 内容结束 -->
			</section>
		</div>
		<%@ include file="/WEB-INF/views/pagelet/footer.jsp"%>
	</div>
</body>

<script>
	$table = $('#table');
	$table.bootstrapTable({
		url : webroot + "/sysresource/getdata",
		toolbar : "#toolbar",
		sortName: 'parent_resource_id asc,order_number',
        sortOrder: 'asc',
		method : "POST",
		pagination : true,
		sidePagination : "server",
		contentType: "application/x-www-form-urlencoded",
		columns:[
			{
				field: 'checkbox',
		    	checkbox: true,
		    	align: 'center'
			},{
				title: 'id',
				field: 'id',
				visible: false
			},{
				title: '资源ID',
				field: 'resourceId'
			},{
				title: '资源名称',
				field: 'resourceName'
			},{
				title: '资源类型',
				field: 'resourceTypeZh'
			},{
				title: '资源地址',
				field: 'url'
			},{
				title: '父级资源ID',
				field: 'parentResourceId'
			},{
				title: '父级资源名称',
				field: 'parentResourceName'
			},{
				title: '资源图标',
				field: 'iconClass',
				formatter : function(value,row,index){
					if(value != null && value != ""){
						return "<span class='fa " + value + "'><span/>&nbsp;&nbsp;" + value;
					} else {
						return "-";
					}
				}
			},{
				title: '资源序号',
				field: 'orderNumber'
			},{
				title: '创建时间',
				field: 'createTime',
				formatter: $appTable.dateFormatter
			}]
	});
	$appTable.click($table,function(){
		$('#del').prop('disabled', !$appTable.getSelections($table).length);
		$('#update').prop('disabled', !$appTable.getSelections($table).length);
	});
	
	
	function add(){
		var rows = $appTable.getSelections($table);
		layer.open({
			type: 2,
			title: '新增资源',
			shadeClose: true,
			shade: 0.8,
			area: ['600px', '550px'],
			content: webroot +'/sysresource/showmodify',
			end: function(){
				$table.bootstrapTable("refresh");
			}
		});
	}

	function update(){
		var rows = $appTable.getSelections($table);
		if(rows.length > 1 || rows.length == 0){
			app.print.error("请选择一个需要修改的数据!", null,null)
			return;
		}
		layer.open({
			type: 2,
			title: '修改资源',
			shadeClose: true,
			shade: 0.8,
			area: ['600px', '550px'],
			content: webroot +'/sysresource/showmodify?id=' + rows[0].id,
			end: function(){
				$table.bootstrapTable("refresh");
			}
		});
	}
	
	function del(){
		var ids = new Array();
		var rows = $appTable.getSelections($table);
		if(rows.length == 0){
			return;
		}
		for(var i=0;i<rows.length;i++){
			ids[i] = rows[i].id;
		}
		app.print.confirm("确定要删除选中的数据吗？",
			function(){
				$.ajax({
					type: "POST",
					url: webroot + "/sysresource/del",
					data: {
						"id[]":ids
		    	 	},
		     		dataType: "json",
		     		success: function(resp){
						if(resp.success){
							app.print.success("删除成功!", null,null)
							$table.bootstrapTable("refresh");
						}
		        	}
				});
			}
		);
	}
	
</script>

</html>
